package com.tencent.tws.watchfacelib;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.RectF;
import android.provider.Settings;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

import cn.zyl.watchfaceblackfashion.FashionFace;

/**
 * Created by zyl on 2016/7/7.
 */
public class ZylUtils {

    /**
     * 获得当前屏幕亮度值 0--255
     */
    public static int getScreenBrightness(Context context){
        int screenBrightness=255;
        try{
            screenBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return screenBrightness;
    }

    /**
     * 设置当前屏幕亮度值 0--255
     */
    public synchronized static void saveScreenBrightness(Context context,int paramInt){
        try{
            Log.d("zyltest","设置亮度为:"+paramInt);
            int cc = getScreenBrightness(context);
            if (cc!=paramInt){
                FashionFace.changeMySelf = true;
                Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, paramInt);
            }else{
                Log.d("zyltest","亮度没变化:"+paramInt);
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }


    // 根据亮度值修改当前window亮度
//    public static void changeAppBrightness(Context context, int brightness) {
//        Window window = ((Activity) context).getWindow();
//        WindowManager.LayoutParams lp = window.getAttributes();
//        if (brightness == -1) {
//            lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
//        } else {
//            lp.screenBrightness = (brightness <= 0 ? 1 : brightness) / 255f;
//        }
//        window.setAttributes(lp);
//    }

}
